#include <algorithm>
#include <cstdint>
#include <cstdio>
#include <vector>

/**
 * Luogu P1182 Array Split
 * This solution uses binary search, reducing time complexity to O(N *
 * log(sum(A))).
 */

std::vector<int> array;

bool check(uint64_t maxSum, int split) {
    int begin = 0, end = 0, count = 0;
    uint64_t sum = 0;
    while (begin < array.size()) {
        if (end == array.size()) {
            count++;
            break;
        }
        int newSum = sum + array[end];
        if (newSum > maxSum) {
            count++;
            begin = end;
            sum = 0;
        } else {
            sum = newSum;
            end++;
        }
    }
    return count <= split;
}

int main() {
    // Input
    int len, split;
    scanf("%d %d", &len, &split);
    array = std::vector<int>(len);
    uint64_t sum = 0, max = 0;
    for (int i = 0; i < len; i++) {
        int val;
        scanf("%d", &val);
        array[i] = val;
        sum += val;
        max = std::max<uint64_t>(max, val);
    }

    // Binary search [max{a_i}, \sum_{i=1}^n a_i]
    uint64_t low = max, high = sum, ans;
    while (low <= high) {
        uint64_t mid = (low + high) / 2;
        if (check(mid, split)) {
            ans = mid;
            high = mid - 1;
        } else
            low = mid + 1;
    }
    printf("%lld\n", ans);

    return 0;
}

/**
 * The following solution only passes 2 cases, while TLE on 3 cases.
 * DP on sections has worst time complexity O(M * N^2), which is not desirable
 * on large inputs.
 */

/*
int main() {
    // Input
    int len, nSplit;
    scanf("%d %d", &len, &nSplit);
    std::vector<uint64_t> preSum(len + 1);
    preSum[0] = 0;
    for (int i = 0; i < len; i++) {
        int val;
        scanf("%d", &val);
        preSum[i + 1] = preSum[i] + val;
    }

    // DP on sections
    auto buf = preSum;
    for (int s = 2; s <= nSplit; s++) {
        auto newBuf = buf;
        for (int i = s; i <= len; i++) {
            uint64_t minMaxSum = UINT64_MAX;
            for (int j = s - 1; j < i; j++) {
                uint64_t maxSum = std::max(buf[j], preSum[i] - preSum[j]);
                minMaxSum = std::min(minMaxSum, maxSum);
            }
            newBuf[i] = minMaxSum;
        }
        buf.swap(newBuf);
    }
    printf("%lld\n", buf[len]);

    return 0;
}
*/